package com.linjiahao.userservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linjiahao.userservice.entity.OnlineLive;
import com.linjiahao.userservice.entity.UcenterMember;
import com.linjiahao.userservice.entity.vo.onlineVo;
import com.linjiahao.userservice.mapper.OnlineLiveMapper;
import com.linjiahao.userservice.service.OnlineLiveService;
import com.linjiahao.userservice.service.UcenterMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-09-19
 */
@Service
public class OnlineLiveServiceImpl extends ServiceImpl<OnlineLiveMapper, OnlineLive> implements OnlineLiveService {

    @Autowired
    private UcenterMemberService ucenterMemberService;

    @Override
    public List<onlineVo> getAll() {
        List<OnlineLive> onlineLives = this.baseMapper.selectList(null);
        ArrayList<onlineVo> onlineVos = new ArrayList<>();
        for (OnlineLive o:onlineLives) {
            UcenterMember byId = ucenterMemberService.getById(o.getMemberId());
            onlineVo onlineVo = new onlineVo();
            onlineVo.setAvatar(byId.getAvatar());
            onlineVo.setNickname(byId.getNickname());
            onlineVo.setLiveTitle(o.getLiveTitle());
            onlineVo.setIntroduce(o.getIntroduce());
            onlineVo.setId(o.getId());
            onlineVo.setStatus(o.getStatus());
            onlineVos.add(onlineVo);
        }
        return onlineVos;
    }
}
